package com.masterclient.app;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.eoner.common.config.Config;
import com.masterclient.app.modules.main.PrivacyDialog;
import com.eoner.baselib.utils.sp.SPUtils;
import com.gyf.immersionbar.ImmersionBar;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/5/11.  test
 */

public class GuideActivity extends Activity {

    @BindView(R.id.vp)
    ViewPager vp;
    @BindView(R.id.rb1)
    RadioButton rb1;
    @BindView(R.id.rb2)
    RadioButton rb2;
    @BindView(R.id.rb3)
    RadioButton rb3;
    @BindView(R.id.rb4)
    RadioButton rb4;
//    @BindView(R.id.rb5)
//    RadioButton rb5;
    @BindView(R.id.rg)
    RadioGroup rg;

    //test for gitlab commit ,

    int[] images = {R.mipmap.yindao1, R.mipmap.yindao2, R.mipmap.yindao3,R.mipmap.yindao4};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guide);
        ButterKnife.bind(this);
        ImmersionBar.with(this).statusBarDarkFont(true,0.2f).transparentStatusBar().init();
        if (!SPUtils.getInstance().getBoolean(Config.APP_PRIVACY_UPDATE_VERSION,false)){
            new PrivacyDialog(this, new PrivacyDialog.AgreementPrivacy() {
                @Override
                public void onAgreement() {
                }
            }).show();
        }
        rb1.setChecked(true);
        rb1.setEnabled(false);
        rb2.setEnabled(false);
        rb3.setEnabled(false);
        rb4.setEnabled(false);
        vp.setAdapter(new PagerAdapter() {
            @Override
            public int getCount() {
                return images.length;
            }

            @Override
            public boolean isViewFromObject(View view, Object object) {
                return view == object;
            }

            @Override
            public void destroyItem(ViewGroup container, int position, Object object) {
                container.removeView(((View) object));
            }

            @Override
            public Object instantiateItem(ViewGroup container, int position) {
                rg.setVisibility(vp.getCurrentItem() == 3?View.GONE:View.VISIBLE);
                if(position == 3){
                    View view = View.inflate(GuideActivity.this, R.layout.view_guide_3,null);
                    view.findViewById(R.id.tv_in).setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            startActivity(new Intent(GuideActivity.this,MainActivity.class));
                            finish();
                        }
                    });
                    container.addView(view);
                    return view;
                }else {
                    ImageView imageView = new ImageView(GuideActivity.this);
                    imageView.setImageResource(images[position]);
                    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                    container.addView(imageView);
                    return imageView;
                }
            }
        });

        vp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                switch (position){
                    case 0:
                        rb1.setChecked(true);
                        rg.setVisibility(View.VISIBLE);
                        break;
                    case 1:
                        rb2.setChecked(true);
                        rg.setVisibility(View.VISIBLE);
                        break;
                    case 2:
                        rb3.setChecked(true);
                        rg.setVisibility(View.VISIBLE);
                        break;
                    case 3:
                        rb4.setChecked(true);
                        rg.setVisibility(View.GONE);
                        break;
//                    case 4:
//                        rb5.setChecked(true);
//                        rg.setVisibility(View.VISIBLE);
//                        rg.setVisibility(View.GONE);
//                        break;
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
